/*
 * Created by JFormDesigner on Tue Dec 08 17:51:23 CET 2009
 */

package at.jku.pervasive.gui.jformdesigner;

import javax.swing.*;
import javax.swing.border.*;

import at.jku.pervasive.Measurement;
import at.jku.pervasive.TagAssignment;
import at.jku.pervasive.gui.model.TagAssignmentModel;
import at.jku.pervasive.gui.renderer.TagIdColorRenderer;

import com.jgoodies.forms.factories.*;
import com.jgoodies.forms.layout.*;

/**
 * @author SHOCKIE
 */
public class TagAssignmentPanel extends JPanel {
	public TagAssignmentPanel() {
		initComponents();
		
		TagIdColorRenderer renderer = new TagIdColorRenderer();
		leftArmComboBox.setRenderer(renderer);
		rightArmComboBox.setRenderer(renderer);
		chestComboBox.setRenderer(renderer);
		backComboBox.setRenderer(renderer);
		
		// set the models
		leftArmComboBox.setModel(new TagAssignmentModel(TagAssignment.LEFT));
		rightArmComboBox.setModel(new TagAssignmentModel(TagAssignment.RIGHT));
		chestComboBox.setModel(new TagAssignmentModel(TagAssignment.FRONT));
		backComboBox.setModel(new TagAssignmentModel(TagAssignment.BACK));
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Open Source Project license - unknown
		JLabel leftArmLabel = new JLabel();
		leftArmComboBox = new JComboBox();
		JLabel rightArmLabel = new JLabel();
		rightArmComboBox = new JComboBox();
		JLabel chestLabel = new JLabel();
		chestComboBox = new JComboBox();
		JLabel backLabel = new JLabel();
		backComboBox = new JComboBox();
		CellConstraints cc = new CellConstraints();

		//======== this ========
		setName("this");
		setLayout(new FormLayout(
			new ColumnSpec[] {
				new ColumnSpec(ColumnSpec.RIGHT, Sizes.DEFAULT, FormSpec.NO_GROW),
				FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
				new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW)
			},
			new RowSpec[] {
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.LINE_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.LINE_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.LINE_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC
			}));

		//---- leftArmLabel ----
		leftArmLabel.setText("Left arm:");
		leftArmLabel.setName("leftArmLabel");
		add(leftArmLabel, cc.xy(1, 1));

		//---- leftArmComboBox ----
		leftArmComboBox.setName("leftArmComboBox");
		add(leftArmComboBox, cc.xy(3, 1));

		//---- rightArmLabel ----
		rightArmLabel.setText("Right arm:");
		rightArmLabel.setName("rightArmLabel");
		add(rightArmLabel, cc.xy(1, 3));

		//---- rightArmComboBox ----
		rightArmComboBox.setName("rightArmComboBox");
		add(rightArmComboBox, cc.xy(3, 3));

		//---- chestLabel ----
		chestLabel.setText("Chest:");
		chestLabel.setName("chestLabel");
		add(chestLabel, cc.xy(1, 5));

		//---- chestComboBox ----
		chestComboBox.setName("chestComboBox");
		add(chestComboBox, cc.xy(3, 5));

		//---- backLabel ----
		backLabel.setText("Back:");
		backLabel.setName("backLabel");
		add(backLabel, cc.xy(1, 7));

		//---- backComboBox ----
		backComboBox.setName("backComboBox");
		add(backComboBox, cc.xy(3, 7));
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	// Generated using JFormDesigner Open Source Project license - unknown
	private JComboBox leftArmComboBox;
	private JComboBox rightArmComboBox;
	private JComboBox chestComboBox;
	private JComboBox backComboBox;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
	
	public String getBackTagId()
	{
		return (String) backComboBox.getSelectedItem();
	}

	public String getChestTagId()
	{
		return (String) chestComboBox.getSelectedItem();
	}

	public String getLeftTagId()
	{
		return (String) leftArmComboBox.getSelectedItem();
	}

	public String getRightTagId()
	{
		return (String) rightArmComboBox.getSelectedItem();
	}

	public void setLoadedMeasurement(Measurement measurement)
	{
		leftArmComboBox.addItem(measurement.getLeftTagId());
		leftArmComboBox.setSelectedItem(measurement.getLeftTagId());
		
		rightArmComboBox.addItem(measurement.getRightTagId());
		rightArmComboBox.setSelectedItem(measurement.getRightTagId());
		
		chestComboBox.addItem(measurement.getFrontTagId());
		chestComboBox.setSelectedItem(measurement.getFrontTagId());
		
		backComboBox.addItem(measurement.getBackTagId());
		backComboBox.setSelectedItem(measurement.getBackTagId());
	}
}
